package io.ai.arch.java.spring.web.api;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

@RestController
@RequestMapping("spring/web/api")
public class DeferredResultApi {
    DeferredResult<String> deferredResult;
    @GetMapping("DeferredResult")
    public DeferredResult<String> deferredResult() {

        deferredResult = new DeferredResult<>(5000L, () -> "timeout");

        return deferredResult;
    }

//    @Scheduled(cron = "*/10 * * * * *")
    public void schedule() {
        deferredResult.setResult("success");
    }
}
